﻿using CleanArchitecture.Core;
using CleanArchitecture.Core.Handlers;
using CleanArchitecture.Infrastructure.Interfaces.AdminUsers;
using System;
using System.Collections.Generic;

namespace CleanArchitecture.Infrastructure.Entities.AdminUsers
{
    public static class AdminUserExtension
    {
        /// <summary>
        /// Get user's roles correspond to its usr-role mapping
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public static IList<AdminRole> GetAdminRoles(this AdminUser user)
        {
            if (user == null)
                throw new ArgumentNullException(nameof(user));
            var adminuserService = EngineContext.Current.Resolve<IAdminUserService>();
            var userRoles = adminuserService.GetAdminUserRolesByUserId(user.Id);
            if (userRoles == null) throw new NowaException("AdminUser Roles Null");
            return userRoles;
        }
    }
}
